package com.example.android427;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.android427.view.activitys.BaseActivity;
import com.example.android427.view.widgets.MmediaController;


public class BofangActivity extends BaseActivity {

    private android.widget.VideoView player;

    private ImageButton bf_im1;
    private ImageButton bf_im2;
    private Button bt;
    private TextView bf_tv1;
    private TextView bf_tv2;
    int number1 = 8;
    int number2=8;
    private View contentView;
    private View titleView;
    private RelativeLayout playerParent;

    private MmediaController mmediaController;
    @Override
    protected void onCreate() {

        Intent intent = getIntent();
        String data1 = intent.getStringExtra("data1");
        TextView t = findViewById(R.id.bofang_t1);
        t.setText(data1);

        bf_im1= findViewById(R.id.bf_im1);
        bt= (Button)findViewById(R.id.bt);
        bf_im2= findViewById(R.id.bf_im2);
        bf_tv1= findViewById(R.id.bf_tv1);
        bf_tv2= findViewById(R.id.bf_tv2);

        bf_im1. setOnClickListener(new View.OnClickListener()
        {
            //当点击一次鼠标，number就加一次
            @Override
            public void onClick(View arg0)
            {
                if(number1%2==0){
                    number1++;
                    bf_tv1.setText("赞("+number1+")");
                    bf_im1.setImageResource(R.drawable.dianzan2);
                }
                else {
                    number1--;
                    bf_tv1.setText("赞("+number1+")");
                    bf_im1.setImageResource(R.drawable.dianzan) ;
                }
            }
        });
        bf_im2. setOnClickListener(new View.OnClickListener()
        {
            //当点击一次鼠标，number就加一次
            @Override
            public void onClick(View arg0)
            {
                if (number2%2==0){
                    number2++;
                    bf_tv2.setText("已加入书单");
                    bf_im2.setImageResource(R.drawable.xingxing2);
                }else{
                    number2--;
                    bf_tv2.setText("加入书单");
                    bf_im2.setImageResource(R.drawable.xingxing);
                }

            }
        });

    }
    @Override
    protected int getRecrouse() {
        return R.layout.bofang;
    }

    @Override
    protected void initView() {

        player = (android.widget.VideoView) findViewById(R.id.paly_video);
        contentView = findViewById(R.id.contentView);
        titleView = findViewById(R.id.title_view);
        playerParent = (RelativeLayout) findViewById(R.id.player_parent);

        player.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.bofang);
        player.start();

        mmediaController = new MmediaController(this)
                .setTitleBar(titleView)
                .setPlayerParent(playerParent)
                .setPlayer(player)
                .setContentView(contentView)
                .build();
    }

    @SuppressLint("NewApi")
    @Override
    public void onConfigurationChanged(Configuration newConfig) {

        super.onConfigurationChanged(newConfig);
        boolean tag = getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ? false : true;
        mmediaController.switchOrientation(tag);
        fullScreen(!tag ? true : false);
        getSupportActionBar().hide();
    }

    @Override
    public void onBackPressed() {
        if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            return;
        } else {
            super.onBackPressed();
        }
    }
}
